#ifndef USER_LOGIN_DIALOG_H
#define USER_LOGIN_DIALOG_H

#include <QWidget>

#include <memory>

#include "user_register_widget.h"
#include "net/tcp_client.h"

#include "ui_user_login_widget.h"

#define USERNAME_MIN_LENTH  2
#define USERNAME_MAX_LENTH  16

#define PASSWORD_MIN_LENTH  6
#define PASSWORD_MAX_LENTH  16

namespace Ui {
class UserLoginWidget;
}

class UserLoginWidget : public QDialog
{
    Q_OBJECT

public:
    explicit UserLoginWidget(QWidget *parent = nullptr, std::shared_ptr<tcp_client> client = nullptr);
    ~UserLoginWidget();
    bool isLoginSuccess()
    {
        return isLoginSuccess_;
    }

    int onUserLoginResponse(int result, const QString &responseMsg,
        uint32_t uid, const std::string &userName);

    void closeEvent(QCloseEvent *event);

private:
    int onUserLogin(const QString &username, const QString &passwd);


    Ui::UserLoginWidget *ui;
    std::shared_ptr<UserRegisterWidget> registerPtr;
    std::shared_ptr<tcp_client> clientPtr;
    bool isLoginSuccess_ = false;     /* 用户登录是否成功 */
};



#endif // USER_LOGIN_DIALOG_H
